/**
**************************************************************************************
*Founder Effect                                                                      *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com)                            *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
#include "StdAfx.h"

#include "../Resource.h"
#include "../Kernel.h"

#include "SceneManager.h"
#include "Camera.h"

extern Kernel* g_kernel;
/**
============================
Constructor
============================
*/
SceneManager::SceneManager(void)
{ 
    m_currentScene  = NULL;
    m_loadMap       = false;
}

/**
============================
Load a scene into memory
============================
*/
bool  SceneManager::LoadScene( const std::string &file )
{
    if ( m_currentScene ) { m_currentScene->Loading( true ); }

        {    // free old scene
	    UnloadScene();

        g_kernel->LPrintf( ("Attempting to load: " +file +"...").c_str() );
	    // load new scene
        m_currentScene = m_importer.CreateScene( file );
        }

    if ( m_currentScene ) { m_currentScene->Loading( false ); }
    return (m_currentScene == NULL);
}
/**
============================
Unload a scene from memory
============================
*/
void SceneManager::UnloadScene()
{
    if ( m_currentScene ) {
		m_currentScene->FreeScene();
    }
}
/**
============================
Update the scene
============================
*/
void SceneManager::Update(long dt)
{
    //if ( m_loadMap )
    //{
    //    LoadScene( map_f.m_mapLoadData.nextMap );
    //}
}
/**
============================
Draw the scene
============================
*/
void SceneManager::Draw(IRender* r, ICamera* cam)
{
    if ( m_currentScene ) {
        m_currentScene->Draw(r, cam );
    }
}



/**
============================
Deconstructor
============================
*/
SceneManager::~SceneManager(void)
{
	UnloadScene();
	// delete the scene
	if ( m_currentScene ) {
		delete m_currentScene;
		m_currentScene = NULL;
	}
}

